﻿using Pegasus.Diagnostics;
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace Pegasus.Collections
{
	/// <summary>
	/// Extends the <see cref="StreamHashtable"/> and adds the ability to specific a filename.
	/// </summary>
	/// <seealso cref="StreamHashtable"/>
	[Obsolete( "Use the Generic class Pegasus.Collections.Generic.DictionaryAppData", false )]
	[Serializable]
	public class FileHashtable : StreamHashtable
	{
		// Local Instance Values
		[NonSerialized]
		private string m_filename;

		/// <summary>
		/// 
		/// </summary>
		protected FileHashtable( SerializationInfo info, StreamingContext context ) :
			base( info, context )
		{
		}

		/// <summary>
		/// Default Constructor
		/// </summary>
		/// <param name="filename">The fully qualified name of the file, or the relative file name.</param>
		/// <remarks>
		/// If the file does not exist then it will be created.
		/// </remarks>
		public FileHashtable( string filename ) :
			base( File.Open( filename, FileMode.OpenOrCreate ) )
		{
			// Check params
			DebugCode.AssertNotEmpty( filename );

			m_filename = filename;
		}

		/// <summary>
		/// Gets the fully quallifed path of the file.
		/// </summary>
		public string Filename
		{
			get
			{
				return m_filename;
			}
		}
	}
}
